package utils;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

public class LogUtils 
{
	private LogManager lm;
	private Logger logger;
	private FileHandler fh;

	/**
	 * 
	 */
	public LogUtils()
	{
		try 
		{
			lm = LogManager.getLogManager();
		    fh = new FileHandler("log.txt");						//file
		    logger = Logger.getLogger("LogUtils");
		
		    lm.addLogger(logger);
		    logger.setLevel(Level.INFO);
		    //fh.setFormatter(new XMLFormatter());
		    fh.setFormatter(new SimpleFormatter());
		
		    logger.addHandler(fh);
		    //logger.setUseParentHandlers(false);
		    logger.log(Level.INFO, "test 1");
		    logger.log(Level.INFO, "test 2");
		    logger.log(Level.INFO, "test 3");
		    fh.close();
		} 
		catch (Exception e) {
			//P
			System.out.println("Exception thrown: " + e);
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 new LogUtils();
	}

}
